import { API_LIST } from '../../../Api/Api'
import { commonTableList, BuiltInData } from '../Common/common'
import {
    AddDataButton,
    ModDataButton,
    DelDataButton,
    SaveExcelButton,
    ExecuteButton,
    AnnexButton,
    CommonButton,
    MoreActionsButton,
} from '../Common/options'
import { PersonTypeTree, ProjectList } from '../Common/Conversion'

const independenceList = {
    'jtgj.ljkjkf.com': 'organizationUuid',
}

const orgStatus = ['jtgj.ljkjkf.com']

export const Person = async ({ url, OptionsEvent, ClientData, Permission, actionRef }) => {
    const { hostname } = window.location
    Permission = Permission?.find(v => v.targetUrl === url).children
    let data = {
        pageSize: 10,
        params: { pageIndex: 1, OOrganizationName: 'asc@1' },
        independenceSet: {
            title: '组织机构',
            url: 'getOrgTree',
            data: { IsByUserUuid: 1 },
            type: 'TableNavTree001',
            all: true,
        },
        independence: independenceList[hostname],
        get: API_LIST()[`get${url}`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        options: [
            <MoreActionsButton
                title="更多操作"
                type="primary"
                kery="mode"
                data={{
                    actionRef,
                    OptionsEvent,
                    one: { type: 'ExportExcel', api: API_LIST()['getPersonExcel'], tips: '人员Excel导出' },
                    two: { type: 'ExportExcel', api: API_LIST()['getPersonImage'], tips: '人像信息导出' },

                    thr: { type: 'SelectExcel', api: API_LIST()['posPersonRosterExcel'], tips: '导出花名册' },
                    fou: { type: 'SelectExcel', api: API_LIST()['posPersonEntryLeaveExcel'], tips: '导出进出场台账' },
                }}
                items={[
                    Permission.findIndex(v => v.uuid === 'b65ff0f9-360e-4d70-b72d-9a86e6dd7023') !== -1 && {
                        key: 'one',
                        label: '人员Excel导出',
                    },
                    Permission.findIndex(v => v.uuid === '4e50d93c-7dbd-46bb-b2dc-15c9f5823d80') !== -1 && {
                        key: 'two',
                        label: '人像信息导出',
                    },
                    {
                        key: 'thr',
                        label: '导出花名册',
                    },
                    {
                        key: 'fou',
                        label: '导出进出场台账',
                    },
                ]}
            />,

            Permission?.findIndex(v => v.uuid === 'd2c78ed0-a2e5-4d3e-a846-af609b8e0dcb') !== -1 && (
                <AddDataButton
                    key="add"
                    OptionsEvent={OptionsEvent}
                    url={url}
                    type="primary"
                    icon="add"
                    title="新增人员信息"
                />
            ),
        ],
        columns: [
            commonTableList.uuid,
            { ...commonTableList.SearchSort, selectType: 'Person' },
            {
                dataIndex: 'faceAttachmentUuid',
                title: '人脸信息',
                valueType: 'upload',
                valueFile: [1],
                fileUrl: 'fileUrl',
                hideInSearch: true,
                hideInTable: true,
            },
            {
                dataIndex: 'fileUrl',
                title: '人脸信息',
                valueType: 'hidden',
                hideInSearch: true,
                hideInTable: true,
                width: 400,
            },
            {
                ...commonTableList.projectUuid,
                valueEnum: await ProjectList(),
                hideInAdded: true,
                hideInModify: true,
                hideInTable: true,
                hideInSearch: !hostname.includes('jszx'),
            },
            {
                ...commonTableList.organizationUuid,
                valueEnum: ClientData.organization,
                hideInSearch: orgStatus.includes(hostname),
                hideInTable: orgStatus.includes(hostname),
            },
            {
                dataIndex: 'personTypeUuid',
                title: '人员类别',
                valueType: 'treeSelect',
                fieldProps: {
                    options: await PersonTypeTree(),
                    fieldNames: { label: 'tableName', value: 'uuid' },
                },
                rules: true,
                hideInTable: true,
                hideInSearch: true,
                width: 150,
            },
            {
                dataIndex: 'personTypeName',
                title: '人员类别',
                valueType: 'input',
                hideInAdded: true,
                hideInModify: true,
                hideInSearch: true,
                width: 200,
            },
            {
                dataIndex: 'faceConfirmed',
                title: '人脸审核',
                valueType: 'select',
                valueEnum: BuiltInData.Pass,
                rules: true,
                width: 150,
            },
            { ...commonTableList.tableName, title: '姓名' },
            {
                dataIndex: 'mobile',
                title: '手机号码',
                valueType: 'input',
                rules: true,
                width: 150,
            },
            {
                dataIndex: 'idCard',
                title: '身份证',
                valueType: 'input',
                rules: true,
                width: 200,
                hideInSearch: true,
            },
            {
                dataIndex: 'personNumber',
                title: '人员编号',
                valueType: 'input',
                rules: true,
                width: 200,
                hideInSearch: true,
            },
            {
                dataIndex: 'isPartyMember',
                title: '党员',
                valueType: 'select',
                valueEnum: BuiltInData.isYes,
                rules: true,
                width: 150,
            },
            {
                dataIndex: 'gender',
                title: '性别',
                valueType: 'select',
                valueEnum: BuiltInData.gender,
                rules: true,
                width: 150,
                hideInSearch: true,
            },
            {
                dataIndex: 'age',
                title: '年龄',
                valueType: 'inputNumber',
                width: 150,
                hideInSearch: true,
            },
            {
                dataIndex: 'certs',
                title: '证书',
                valueType: 'input',
                width: 150,
                hideInSearch: true,
                // rules: true,
            },

            {
                dataIndex: 'emergenceName',
                title: '紧急联系人姓名',
                valueType: 'input',
                width: 150,
                hideInSearch: true,
                // rules: true,
            },

            {
                dataIndex: 'emergenceMobile',
                title: '紧急联系人电话',
                valueType: 'input',
                width: 150,
                hideInSearch: true,
            },
            {
                dataIndex: 'entryTime',
                title: '进场时间',
                valueType: 'Date',
                width: 150,
                rules: true,
                hideInSearch: true,
            },
            {
                dataIndex: 'leaveTime',
                title: '退场时间',
                valueType: 'Date',
                width: 150,
                // rules: true,
                hideInSearch: true,
            },
            {
                dataIndex: 'departmentUuid',
                title: '部门',
                valueType: 'select',
                valueEnum: ClientData.dictionary['a2891f3b-3811-4b8b-8dbb-832096e3174e'],
                rules: true,
                width: 150,
                hideInAdded: !hostname.includes('jtgj'),
                hideInModify: !hostname.includes('jtgj'),
                hideInTable: !hostname.includes('jtgj'),
                hideInSearch: !hostname.includes('jtgj'),
            },
            {
                dataIndex: 'positionUuid',
                title: '岗位',
                valueType: 'select',
                valueEnum: ClientData.dictionary['d4d706cd-1538-456b-90da-d061195c8aa6'],
                rules: true,
                width: 150,
                hideInAdded: !hostname.includes('jtgj'),
                hideInModify: !hostname.includes('jtgj'),
                hideInTable: !hostname.includes('jtgj'),
                hideInSearch: !hostname.includes('jtgj'),
            },
            {
                dataIndex: 'rankUuid',
                title: '职务级别',
                valueType: 'select',
                valueEnum: ClientData.dictionary['d83de24e-191d-4646-b742-55ad694a3747'],
                rules: true,
                width: 150,
                hideInAdded: !hostname.includes('jtgj'),
                hideInModify: !hostname.includes('jtgj'),
                hideInTable: !hostname.includes('jtgj'),
                hideInSearch: !hostname.includes('jtgj'),
            },
            {
                dataIndex: 'categoryUuid',
                title: '人员性质',
                valueType: 'select',
                valueEnum: ClientData.dictionary['51297964-6295-475a-8219-d3f9a4568fe6'],
                rules: true,
                width: 150,
                hideInAdded: !hostname.includes('jtgj'),
                hideInModify: !hostname.includes('jtgj'),
                hideInTable: !hostname.includes('jtgj'),
                hideInSearch: !hostname.includes('jtgj'),
            },

            {
                dataIndex: 'laborCompany',
                title: '劳务公司',
                valueType: 'input',
                width: 150,
                hideInAdded: !hostname.includes('jtgj'),
                hideInModify: !hostname.includes('jtgj'),
                hideInTable: !hostname.includes('jtgj'),
                hideInSearch: !hostname.includes('jtgj'),
            },
            {
                dataIndex: 'dailyWage',
                title: '日工资',
                valueType: 'inputNumber',
                width: 150,
                hideInAdded: !hostname.includes('jtgj'),
                hideInModify: !hostname.includes('jtgj'),
                hideInTable: !hostname.includes('jtgj'),
                hideInSearch: !hostname.includes('jtgj'),
            },
            {
                dataIndex: 'creditCardNum',
                title: '银行卡号',
                valueType: 'input',
                width: 150,
                hideInAdded: !hostname.includes('jtgj'),
                hideInModify: !hostname.includes('jtgj'),
                hideInTable: !hostname.includes('jtgj'),
                hideInSearch: !hostname.includes('jtgj'),
            },
            {
                dataIndex: 'bankName',
                title: '开户银行',
                valueType: 'input',
                width: 150,
                hideInAdded: !hostname.includes('jtgj'),
                hideInModify: !hostname.includes('jtgj'),
                hideInTable: !hostname.includes('jtgj'),
                hideInSearch: !hostname.includes('jtgj'),
            },

            {
                dataIndex: 'address',
                title: '详细地址',
                valueType: 'textarea',
                width: 150,
                hideInSearch: true,
            },

            commonTableList.createUserName,
            commonTableList.createTime,
            commonTableList.updateUserName,
            commonTableList.updateTime,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 540,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { uuid, faceAttachmentUuid, fileUrl, faceConfirmed } = record
                    return [
                        hostname === 'jtgj.ljkjkf.com' && (
                            <CommonButton
                                key="submit"
                                OptionsEvent={OptionsEvent}
                                title="人员档案"
                                data={{
                                    type: 'FileManagement',
                                    classification: 'person',
                                    record,
                                    width: 1000,
                                }}
                            />
                        ),

                        fileUrl && <AnnexButton OptionsEvent={OptionsEvent} key="see" url={fileUrl} title="人脸信息" />,
                        Permission.findIndex(v => v.uuid === '49aa73dd-0a00-430a-90ec-e965c5ce46a4') !== -1 && (
                            <ModDataButton
                                OptionsEvent={OptionsEvent}
                                key="modify"
                                title="修改"
                                url={url}
                                data={record}
                            />
                        ),
                        Permission.findIndex(v => v.uuid === '31bf27c6-c7a5-415c-8119-0cecf72c7434') !== -1 && (
                            <ExecuteButton
                                actionRef={actionRef}
                                key="UpLoadUserBtn"
                                title="上传信息"
                                url="posPersonUpLoadPerson"
                                path={[uuid]}
                                tips="信息上传成功!"
                            />
                        ),
                        Permission.findIndex(v => v.uuid === 'b23ab186-846e-4444-9ecd-d22d580c8f57') !== -1 &&
                            faceAttachmentUuid &&
                            faceConfirmed === 0 && (
                                <ExecuteButton
                                    actionRef={actionRef}
                                    key="one"
                                    title="人脸审核"
                                    url="posFaceConfirmed"
                                    data={{ uuid, faceConfirmed: 1 }}
                                    tips="人脸审核成功!"
                                />
                            ),
                        Permission.findIndex(v => v.uuid === 'b23ab186-846e-4444-9ecd-d22d580c8f57') !== -1 &&
                            faceAttachmentUuid &&
                            faceConfirmed === 1 && (
                                <ExecuteButton
                                    actionRef={actionRef}
                                    key="two"
                                    title="取消审核"
                                    url="posFaceConfirmed"
                                    danger={true}
                                    data={{ uuid, faceConfirmed: 0 }}
                                    tips="取消审核成功!"
                                />
                            ),
                        Permission.findIndex(v => v.uuid === 'af811341-2631-460a-8d2d-d5f88194d9c8') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url={url}
                                uuid={record.uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }
    return data
}
